package com.team.RunsFast_Api.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.team.RunsFast_Api.dto.CouponDto;
import com.team.runsfast.entity.Coupon;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CouponDao extends BaseMapper<Coupon> {

    @Update("update t_coupon set num=num-1 where id=#{id}")
    int updateCoupon(long id);

    @Select("SELECT tc.*,tci.ctime,tci.id coupinfoid FROM t_coupon tc \n" +
            "inner join t_couponinfo tci on tc.id=tci.coupid \n" +
            "where tc.id=#{id} and flag=1")
    List<CouponDto> selectByIds(long id);

    @Select("SELECT tc.*,tci.ctime,tci.id coupinfoid FROM t_coupon tc " +
            "inner join t_couponinfo tci on tc.id=tci.coupid " +
            "where tc.id=#{id} and flag=1 and tci.id=#{coupinfoid}")
    List<CouponDto> selectByIds2(@Param("id") long id, @Param("coupinfoid") long coupinfoid);
}
